import { writable } from "svelte/store";

// Markdown 内容状态
export const markdown = writable("");

// Crepe API 状态
export const crepeAPI = writable({
  loaded: false,
  onShare: () => {},
  update: () => {},
  setDisabled: () => {},    // 新增禁用方法
  isDisabled: () => false, // 新增状态查询方法
  toggleDisabled: () => {}, // 新增切换方法
});

// CodeMirror API 状态
export const cmAPI = writable({
  loaded: false,
  update: () => {},
});

// 焦点类型
export const focus = writable(null);

// 编辑器禁用状态
export const editorDisabled = writable(false);

// 自定义 store 创建函数（可选，提供更好的 API）
export function createPlaygroundStores() {
  return {
    markdown: writable(""),
    crepeAPI: writable({
      loaded: false,
      onShare: () => {},
      update: () => {},
      setDisabled: () => {},
      isDisabled: () => false,
      toggleDisabled: () => {},
    }),
    cmAPI: writable({
      loaded: false,
      update: () => {},
    }),
    focus: writable(null),
    editorDisabled: writable(false), // 新增禁用状态
  };
}
